package com.qunar.tech.team12.hotel.parser;

import com.google.common.base.Splitter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;

/**
 * Created by mzy on 14-7-21.
 */
public class QueryParser implements Parser<Query> {

    private static final Splitter AND = Splitter.on("&");
    private static final Splitter EQ = Splitter.on("=");
    private static final Splitter COMMA = Splitter.on(",");
    private final Map<String, String> param = new HashMap<String, String>();
    private final Logger LOG = LoggerFactory.getLogger(this.getClass());

    @Override
    public Iterator<Query> parse(Scanner scanner) {
        return null;
    }

    @Override
    public Query parse(String str) {
        Iterator<String> kv = AND.split(str).iterator();
        Query queyr = new Query();
        while (kv.hasNext()) {
            String s = kv.next();
            LOG.debug(s);
            Iterator<String> dkv = EQ.split(s).iterator();
            String k = "", v = "";
            if (dkv.hasNext()) k = dkv.next();
            if (dkv.hasNext()) v = dkv.next();
            Query.ParamType.valueOf(k.toUpperCase()).setProperty(v,queyr);
        }
        return queyr;
    }
}
